<style lang="less">
  @import '../styles/common.less';
  @import './index.less';
  @import '../tables/components/table.less';
</style>

<template>
  <div class="chat">
    <Row class="row">
      <Col span="6" class="list-div session-list-div">
      <Card>
        <!--<p slot="title">
          最近联系人
        </p>-->
        <div class="session-div">
          <ul class=" chat-listsession-ul" id="session-ul">
            <li class="chat-item" v-for="el in messageList" @click="onUpdateMsg(el)"
                v-bind:class="[el.id == sid ? 'bac-session' : '']">
              <div class="chat-portrait-box">
                <!--<div class="chatimgdiv" v-if="el.img == ''" v-text="el.imgNickName"
                     v-bind:class="{'chatimgdivGroup': (el.scene=='team' && !(el.idtype=='system' || el.idtype=='gonggao' || el.idtype=='richeng')),
                 'chatimgdivGonggao': (el.idtype=='system' || el.idtype=='gonggao' || el.idtype=='richeng')}">
                </div>-->
                <img class="chatimg" src="/vendors/images/group.png"
                     v-if="el.img == '' && (el.scene=='team' && !(el.idtype=='system' || el.idtype=='gonggao' || el.idtype=='richeng'))"/>
                <img class="chatimg" src="/vendors/images/person.png"
                     v-if="el.img == '' && (el.scene=='p2p' && !(el.idtype=='system' || el.idtype=='gonggao' || el.idtype=='richeng'))"/>
                <img class="chatimg" src="/vendors/images/notice.png"
                     v-if="el.img == '' && (el.idtype=='system' || el.idtype=='gonggao' || el.idtype=='richeng')"/>
                <img class="chatimg" :src="el.img" v-if="el.img != ''"/>
              </div>
              <div class="chat-item-main">
                <div class="chat-item-row time-period">
                  <h3 class="chat-item-name" v-text="el.nickName"></h3>
                  <span class="chat-item-row-right time" v-text="el.time"></span>
                </div>
                <div class="chat-item-row badge-period ellipsis-div">
                  <p class="chat-new-info ellipsis ellipsis-div"
                     v-text="el.text"
                  ></p>
                  <span class="chat-item-row-right badge"
                        v-if="el.num > 0"
                        v-text="el.num"
                  ></span>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </Card>
      </Col>
      <Col span="18" class="padding-left-10 list-div">
      <Card id="mag-card" class="mag-card">
        <p slot="title">
          <span v-text="titleName"></span>
          <span class="title-menus" @click="showChatDetail()">
            <Icon type="ios-person" v-if="scene == 'p2p'" class="title-menus-i"></Icon>
            <Icon type="ios-people" v-if="scene == 'team'" class="title-menus-i"></Icon>
          </span>
        </p>
        <Row class="margin-top-10 msg-div" id="msg-div">
          <div v-for="el in messagesData">
            <div class="div-left" v-if="el.messages_type == 'received'
              && ((el.type != 'notification') && !(el.type == 'custom' && el.content.type == 'deleteMsg')) && systemPage != true">
              <table border="0" cellspacing="0" cellpadding="0" class="table">
                <tr>
                  <td style="width: 50px;" align="left" valign="top">
                    <!--<div class="hadeimg-div" v-if="el.img == ''" v-text="el.imgNickName"></div>-->
                    <img class="hadeimg" v-if="el.img != ''" :src="el.img"/>
                    <img class="hadeimg" v-if="el.img == ''" src="/vendors/images/person.png"/>
                  </td>
                  <td>
                    <div class="liaotiandivLname" v-text="el.fromNick"></div>
                    <div class="liaotiandivLtime" v-text="el.time"></div>
                    <div class="liaotiandivL speech_left"
                         @contextmenu.prevent="contextmenuFun(el, $event)"
                         v-html="el.text"
                         v-if="el.type == 'text'"></div>
                    <div class="liaotiandivL speech_left" v-if="el.type == 'file'"
                         @contextmenu.prevent="contextmenuFun(el, $event)">
                      <div class="file" v-if="el.file.type != 'img'" @click="DownloadFile(el.file.url, el.file.name)">
                        <div class="filename div-line" v-text="el.file.name"></div>
                        <div class="filename div-line" v-text="el.file.size"></div>
                      </div>
                      <div class="file_img" v-if="el.file.type == 'img'">
                        <img :src="el.file.url">
                      </div>
                    </div>
                    <div class="liaotiandivL speech_left chat-item-team-notice"
                         v-if="(el.type == 'custom' && el.content.type == 'card')"
                         @contextmenu.prevent="contextmenuFun(el, $event)"
                         @click="teamNoticeDetail(el.content.data)">
                      <div class="team-notice">
                        <span class="fromNickspan span">群公告</span>
                      </div>
                      <div class="team-notice-title">
                        <span v-text="el.content.data.title" class="fromNickspan span"></span>
                      </div>
                    </div>
                  </td>
                </tr>
              </table>
            </div>
            <div class="div-right" v-if="el.messages_type == 'sent'
                && ((el.type != 'notification') && !(el.type == 'custom' && el.content.type == 'deleteMsg')) && systemPage != true">
              <table border="0" cellspacing="0" cellpadding="0" class="table">
                <tr>
                  <td style="text-align: right;">
                    <div class="liaotiandivRname">
                      <span v-text="el.fromNick"></span>
                      <span class="read" v-if="el.messages_type=='sent' && el.scene=='p2p'"
                            v-bind:class="[el.isRead==true ? '' : 'unread']">
                        {{el.isRead == true ? '已读' : '未读'}}
                      </span>
                    </div>
                    <div class="liaotiandivRtime" v-text="el.time"></div>
                    <div class="liaotiandivR speech_right"
                         @contextmenu.prevent="contextmenuFun(el, $event)"
                         v-html="el.text"
                         v-if="el.type == 'text'"></div>
                    <div class="liaotiandivR speech_right"
                         @contextmenu.prevent="contextmenuFun(el, $event)"
                         v-if="el.type == 'file'">
                      <div class="file" v-if="el.file.type != 'img'" @click="DownloadFile(el.file.url, el.file.name)">
                        <div class="filename div-line" v-text="el.file.name"></div>
                        <div class="filename div-line" v-text="el.file.size"></div>
                      </div>
                      <div class="file_img" v-if="el.file.type == 'img'">
                        <img :src="el.file.url">
                      </div>
                    </div>
                    <div class="liaotiandivR speech_right chat-item-team-notice"
                         v-if="(el.type == 'custom' && el.content.type == 'card')"
                         @contextmenu.prevent="contextmenuFun(el, $event)"
                         @click="teamNoticeDetail(el.content.data)">
                      <div class="team-notice">
                        <span class="fromNickspan span">群公告</span>
                      </div>
                      <div class="team-notice-title">
                        <span v-text="el.content.data.title" class="fromNickspan span"></span>
                      </div>
                    </div>
                  </td>
                  <td style="width: 50px;" align="left" valign="top">
                    <!--<div class="hadeimg-div" v-if="el.img == ''" v-text="el.imgNickName"></div>-->
                    <img class="hadeimg" v-if="el.img != ''" :src="el.img"/>
                    <img class="hadeimg" v-if="el.img == ''" src="/vendors/images/person.png"/>
                  </td>
                </tr>
              </table>
            </div>
            <!--系统通知-->
            <div class="div-left" v-if="systemPage == true">
              <table border="0" cellspacing="0" cellpadding="0" class="table">
                <tr>
                  <td style="width: 50px;" align="left" valign="top">
                    <!--<div class="hadeimg-div" v-if="el.img == ''" v-text="el.imgNickName"></div>-->
                    <img class="hadeimg" v-if="el.img != ''" :src="el.img"/>
                    <img class="hadeimg" v-if="el.img == ''" src="/vendors/images/person.png"/>
                  </td>
                  <td>
                    <div class="liaotiandivLname" v-text="el.fromNick"></div>
                    <div class="liaotiandivLtime" v-text="el.time"></div>
                    <div class="liaotiandivL speech_left"
                         v-html="el.text"></div>
                  </td>
                </tr>
              </table>
            </div>
            <!--群通知-->
            <div class="notification" v-if="(el.type == 'notification' && el.addTeamMembers != '')">
              <span class="span" v-if="el.attach.type == 'addTeamMembers'">
                <span v-text="el.addTeamMembers"></span>
                被邀请加入该群组
              </span>
              <span class="span" v-if="el.attach.type == 'leaveTeam'">
                <span v-text="el.addTeamMembers"></span>
                已退出该群组
              </span>
              <span class="span" v-if="el.attach.type == 'removeTeamMembers'">
                <span v-text="el.addTeamMembers"></span>
                被移除该群组
              </span>
              <span class="span" v-if="el.attach.type == 'addTeamManagers'">
                <span v-text="el.addTeamMembers"></span>
                被提升为群管理员
              </span>
              <span class="span" v-if="el.attach.type == 'removeTeamManagers'">
                <span v-text="el.addTeamMembers"></span>
                被取消群管理员权限
              </span>
              <span class="span" v-if="el.attach.type == 'transferTeam'">
                <span v-text="el.addTeamMembers"></span>
                成为群主
              </span>
              <span class="span" v-if="el.attach.type == 'updateTeam'">
                <span v-text="el.addTeamMembers"></span>
                群名称更改为：{{el.attach.team.name}}
              </span>
            </div>
            <!--撤销-->
            <div class="notification" v-if="(el.type == 'custom' && el.content.type == 'deleteMsg')">
              <span class="span">
                {{el.content.data.name || ''}}{{el.content.data.text || ''}}
              </span>
            </div>
          </div>
          <poptip v-model="contextmenuModel" class="contextmenuPoptip" placement="bottom">
            <div slot="content" class="div" @click="forwardingFun()" v-if="isTeamNotice != true">
              转发
            </div>
            <div slot="content" class="div" @click="undoFun()" v-if="isUndoMsg == true">
              撤销
            </div>
            <div slot="content" class="div" @click="deleteFun()">
              删除
            </div>
          </poptip>
        </Row>
        <Row class=" menus-div" v-if="systemPage!=true">
          <span>
            <Icon type="md-happy" class="menus-i"></Icon>
          </span>
          <span @click="GetFile()">
            <Icon type="ios-copy-outline" class="menus-i"></Icon>
          </span>
          <span @click="addTeamNotice()" v-if="scene == 'team'">
            <Icon type="md-volume-up" class="menus-i"></Icon>
          </span>

          <input type="file" id="chatDFileUrl" @change="sendFileClick()" style="display: none;"/>
        </Row>
        <Row class=" textarea-div" v-if="systemPage!=true">
          <textarea id="textarea_val" class="textarea_val" v-model="textarea_val"></textarea>
        </Row>
        <Row class=" send-div" v-if="systemPage!=true">
          <Button class="send-button" @click="sendMessage()">发送</Button>
        </Row>
      </Card>
      </Col>
      <Col span="18" class="padding-left-10 list-div Col-heid-div" v-show="showChatList == false">
      <Card></Card>
      </Col>
      <Col span="6" class="padding-left-10 list-div Col-heid-div" v-if="showChatDetailPage == true">
      <Card class="bac-eee ChatDetailPage-Card">
        <p slot="title" @click="" style="cursor: pointer;" @click="heidChatDetail()">
          详细信息
          <Icon type="ios-arrow-forward" style="margin-left: 16px;"></Icon>
        </p>
        <div class="ChatDetailPage-div">
          <ul class="ulmenu">
            <li v-for="el in ChatDetailImage" class="cursor" @click="searchUserInfo(el.id)">
              <!--<div class="img-div" v-if="el.thumb==''" v-text="el.imgNickName"></div>-->
              <img :src="el.thumb" v-if="el.thumb!=''" alt="" class="li_img">
              <img src="/vendors/images/person.png" v-if="el.thumb==''" alt="" class="li_img">
              <div class="li_div div-line" v-text="el.name"></div>
            </li>
            <li v-if="scene == 'p2p'">
              <div class="li_add" @click="p2pShowChooseUserModal()">
                <Icon type="md-add" size="30"></Icon>
              </div>
            </li>
            <li v-if="scene == 'team'">
              <div class="li_add" @click="showChooseUserModal()">
                <Icon type="md-add" size="30"></Icon>
              </div>
            </li>
            <li v-if="scene == 'team' && (teamOwner == true || teamAdmins == true)">
              <div class="li_add" @click="delTeamMembers()">
                <Icon type="md-remove" size="30"/>
              </div>
            </li>
          </ul>
        </div>
        <div class="ChatDetailPage-content" v-if="scene == 'team'">
          <Form label-position="right">
            <FormItem label="群名称">
              <div class="ChatDetailPage-dataDetail-div">
                <span v-text="TeamDetailObj.name"></span>
                <span class="span-menu" @click="showUpdateTeamName()" v-if="teamOwner == true || teamAdmins == true">
                  <Icon type="md-create"/>
                </span>
              </div>
            </FormItem>
            <FormItem label="调整群管理员" v-if="scene == 'team' && (teamOwner == true || teamAdmins == true)">
              <div class="ChatDetailPage-dataDetail-div">
                <span class="span-menu" @click="showUpdateTeamAdmins()" v-if="teamOwner == true || teamAdmins == true">
                  <Icon type="md-create"/>
                </span>
              </div>
            </FormItem>
            <FormItem label="转让群" v-if="scene == 'team' && (teamOwner == true)">
              <div class="ChatDetailPage-dataDetail-div">
                <span class="span-menu" @click="showUpdateTeamOwner()" v-if="teamOwner == true || teamAdmins == true">
                  <Icon type="md-create"/>
                </span>
              </div>
            </FormItem>
          </Form>
        </div>

        <div class="ChatDetailPage-div-Button" v-if="scene == 'team'">
          <div class="div bac-eee">
            <Button @click="quitTeam()" v-if="teamBig == false && teamOwner != true">退出群组</Button>
            <Button @click="delTeam()" v-if="teamBig == false && teamOwner == true">解散群组</Button>
          </div>
        </div>
      </Card>
      </Col>
      <Modal v-model="addTeamNoticeModal" :closable='false' :mask-closable=false :width="600">
        <h3 slot="header" style="color:#2D8CF0">创建群公告</h3>
        <Form ref="dep" :model="addTeamNoticeFrom" :label-width="100" label-position="right"
              :rules="addTeamNoticeValidate">
          <FormItem label="公告标题" prop="title">
            <Input v-model="addTeamNoticeFrom.title" placeholder="请输入标题"></Input>
          </FormItem>
          <FormItem label="公告内容" prop="content">
            <Input v-model="addTeamNoticeFrom.content" type="textarea" :autosize="{minRows: 5,maxRows: 5}"
                   placeholder="请输入内容" class="textarea"></Input>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="cancelTeamNotice">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveTeamNotice">保存</Button>
        </div>
      </Modal>
      <Modal :width="600" title="群公告详情"
             v-model="showTeamNoticeDetailModal"
             ok-text="确定"
             cancel-text="取消"
             @on-ok=""
             @on-cancel=""
             class-name="vertical-center-modal"
             class="Modal-Detail-div">
        <Form label-position="top">
          <FormItem label="创建人" v-if="TeamNoticeDetailObj.user">
            <div class="dataDetail-div" v-text="TeamNoticeDetailObj.user.name"></div>
          </FormItem>
          <FormItem label="标题">
            <div class="dataDetail-div" v-text="TeamNoticeDetailObj.title"></div>
          </FormItem>
          <FormItem label="内容">
            <div class="dataDetail-div" v-html="TeamNoticeDetailObj.content"></div>
          </FormItem>
          <FormItem label="创建时间">
            <div class="dataDetail-div" v-text="TeamNoticeDetailObj.create_time"></div>
          </FormItem>
          <FormItem label="人员阅读状态">
            <div class="dataDetail-div padding-0">
              <Table stripe border :columns="readList_columns" :data="readList"></Table>
              <div class="readList_page_div text-align-center" v-if="readList_total > 0">
                <Page :total="readList_total" :current="readList_page" size="small" @on-change="readList_changePage"
                      show-elevator></Page>
              </div>
            </div>
          </FormItem>
        </Form>
      </Modal>
      <!--选择人员-->
      <Modal v-model="chooseUserModal" :closable='false' :mask-closable=false :width="600" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">选择人员</h3>
        <Form label-position="top" v-if="p2pChooseUserModal == true">
          <FormItem label="群名称">
            <Input v-model="addTeamName" placeholder="请输入群名称"></Input>
          </FormItem>
        </Form>
        <Tree ref="tree" :data="TreeData" show-checkbox multiple></Tree>
        <div slot="footer">
          <Button type="text" @click="cancelChooseUserModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveChooseUserModal">保存</Button>
        </div>
      </Modal>
      <!--删除群成员-->
      <Modal v-model="delChooseUserModal" :closable='false' :mask-closable=false :width="600" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">删除群成员</h3>
        <Table stripe border @on-selection-change="delUserSelection" :columns="delChooseUserColumns"
               :data="delChooseUserData"></Table>
        <div slot="footer">
          <Button type="text" @click="cancelDelChooseUserModal">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveDelChooseUserModal">确定</Button>
        </div>
      </Modal>
      <!--修改群名称-->
      <Modal v-model="updateTeamNameModal" :closable='false' :mask-closable=false :width="600" class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">修改群名称</h3>
        <Form label-position="top">
          <FormItem label="群名称">
            <Input v-model="updateTeamName" placeholder="请输入群名称"></Input>
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="hideUpdateTeamName">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="updateTeamNameFun">保存</Button>
        </div>
      </Modal>
      <!--调整群管理员-->
      <Modal v-model="updateTeamAdminsModal" :closable='false' :mask-closable=false :width="600"
             class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">调整群管理员</h3>
        <Table stripe border @on-selection-change="updateTeamAdminsSelection" :columns="delChooseUserColumns"
               :data="updateTeamAdminsData"></Table>
        <div slot="footer">
          <Button type="text" @click="hideUpdateTeamAdmins">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveUpdateTeamAdmins">确定</Button>
        </div>
      </Modal>
      <!--转让群-->
      <Modal v-model="updateTeamOwnerModal" :closable='false' :mask-closable=false :width="600"
             class="Modal-Detail-div">
        <h3 slot="header" style="color:#2D8CF0">转让群</h3>
        <Table highlight-row stripe border @on-current-change="updateTeamOwnerCurrent" :columns="updateTeamOwnerColumns"
               :data="updateTeamOwnerData"></Table>
        <div slot="footer">
          <Button type="text" @click="hideUpdateTeamOwner">取消</Button>
          <Button type="primary" :loading="saveLoading" @click="saveUpdateTeamOwner">确定</Button>
        </div>
      </Modal>
      <!--人员详情-->
      <user-info
        :user_id="userInfo_id"
        isChat="chat"
        @userInfoBackFun="userInfoBackFun"
        @toChatFun="toChatFun"
      ></user-info>
    </Row>
  </div>
</template>

<script>
  import Cookies from 'js-cookie';
  import Util from '../../libs/util';
  import Utils from '../../libs/mod.utils';
  import Nim from '../../libs/mod.nim';
  import String from '../../libs/mod.string';
  import userInfo from '../components/user-info.vue';
  export default {
    components: {
      userInfo
    },
    data () {
      return {
        total: 0,
        page: 1,
        size: 10,
        readList_total: 0,
        readList_page: 1,
        contextmenuModel: false,
        showChatList: false,
        showChatDetailPage: false,
        chooseUserModal: false,
        p2pChooseUserModal: false,
        delChooseUserModal: false,
        updateTeamNameModal: false,
        updateTeamAdminsModal: false,
        updateTeamOwnerModal: false,
        addTeamName: '',
        updateTeamName: '',
        messageList: [],
        messagesData: [],
        titleName: '',
        sid: '',
        scene: '',
        toAccount: '',
        textarea_val: '',
        costShowListLength: 50,
        oldshowListLength: 50,
        showListLength: 50,
        lastMsg: null,
        responseInProgress: false,
        showTeamNoticeDetailModal: false,
        addTeamNoticeModal: false,
        saveLoading: false,
        addTeamNoticeFrom: {
          title: '',
          content: '',
        },
        addTeamNoticeValidate: {
          title: [
            {required: true, message: '请输入标题', trigger: 'blur'}
          ],
          content: [
            {required: true, message: '请输入内容', trigger: 'blur'}
          ],
        },
        TeamNoticeDetailObj: {},
        readList: [],
        readList_columns: [
          {
            key: 'name',
            title: '姓名',
          },
          {
            key: 'status',
            title: '阅读状态',
            render: (h, params) => {
              return h('div', [
                h('span', params.row.status == true ? '已读' : '未读')
              ]);
            }
          },
          {
            key: 'read_time',
            title: '阅读时间',
          },
        ],
        ChatDetailImage: [],
        TeamDetailObj: {},
        TreeData: [],
        ChooseDepArr: [],
        ChooseUserArr: [],
        ChooseUsernameArr: [],
        delChooseUserColumns: [
          {
            type: 'selection',
            width: 100,
            align: 'center'
          },
          {
            key: 'name',
            title: '姓名',
          }
        ],
        delChooseUserData: [],
        delUserArr: [],
        teamOwner: false,
        teamAdmins: false,
        teamBig: false,
        updateTeamAdminsData: [],
        updateTeamAdminsUserArr: [],
        updateTeamOwnerData: [],
        updateTeamOwnerUserArr: [],
        updateTeamOwnerColumns: [
          {
            type: 'index',
            width: 100,
            align: 'center'
          },
          {
            key: 'name',
            title: '姓名',
          }
        ],
        teamNotice_id: '',
        checkedMsg: {},
        isTeamNotice: false,//群公告不能转发
        isUndoMsg: false,
        forwarPage: false,
        systemPage: false,// 系统通知
        comePageTime: 0,// 进入页面的时间戳
        userInfo_id: '',// 查看用户详情的用户id
      };
    },
    computed: {},
    beforeMount: function () {
      var _this = this;
      var comePageTime = _this.comePageTime;
      var timestamp = new Date().getTime();
      _this.comePageTime = timestamp;
    },
    beforeDestroy: function () {
      var _this = this;
      var comePageTime = _this.comePageTime;
      var timestamp = new Date().getTime();
      var type = Util.constant.statistical_type.chat.id;
      var seconds = Math.ceil((parseInt(timestamp) - parseInt(comePageTime)) / 1000);
      Util.statistical(_this, type, seconds);//保存数据
    },
    created: function () {
      var _this = this;
      Nim.setVuethis(_this);

      // 通讯录跳转过来的
      var sid2chat = sessionStorage.getItem('sid2chat');
      var name2chat = sessionStorage.getItem('name2chat');
      if (sid2chat && sid2chat != '') {
        _this.sid = sid2chat;
        var Arr = sid2chat.split('-');
        var scene = Arr[0] ? Arr[0] : '';
        var toAccount = Arr[1] ? Arr[1] : '';
        _this.scene = scene;
        _this.toAccount = toAccount;
        if (name2chat && name2chat != '') {
          _this.titleName = name2chat;
        } else {
          _this.titleName = Nim.getUsername(toAccount);
        }
        _this.showChatList = true;

        sessionStorage.removeItem('sid2chat');
        sessionStorage.removeItem('name2chat');
      }
      // 收藏夹跳转过来的
      var collection_list_str = sessionStorage.getItem('collection_list');
      if (collection_list_str && collection_list_str != '') {
        var collection_list_obj = Util.toJson(collection_list_str);
        var id = collection_list_obj.id || '';
        var type = collection_list_obj.type || '';
        sessionStorage.removeItem('collection_list');
      }
    },
    mounted: function () {
      var _this = this;

      _this.$nextTick(function () {
        var height = $('#mag-card').height();
        var H = height - 41 - 101 - 41 - 51 - 10;
        $('#mag-card .msg-div').height(H);
      });
      _this.getSessionData();
    },
    methods: {
      // 查看用户详情
      searchUserInfo: function (id) {
        var _this = this;
        _this.userInfo_id = id;
      },
      userInfoBackFun: function (id) {
        var _this = this;
        _this.userInfo_id = id;
      },
      toChatFun: function (_data) {
        var _this = this;
        _this.userInfo_id = -1;
        var name = _data.name;
        var username = _data.username;
        _this.sid = 'p2p-' + username;
        _this.scene = 'p2p';
        _this.toAccount = username;
        _this.titleName = name;
        _this.showChatList = true;

        var obj = {
          id: _this.sid,
          nickName: name,
        };
        _this.onUpdateMsg(obj);
      },
      // 滚动到最低端
      scrollHeight: function () {
        var _this = this;
        setTimeout(function () {
          var div = document.getElementById('msg-div');
          if (div) {
            div.scrollTop = div.scrollHeight;
          }
        }, 500);
      },
      // 标记为已读
      resetSessionUnread: function (sid, lastMsg) {
        Nim.resetSessionUnread(sid, lastMsg);
      },
      // 清除所有
      clear: function () {
        var _this = this;
        _this.showChatList = false;
        _this.cancelTeamNotice();
        _this.heidChatDetail();
        _this.cancelDelChooseUserModal();
        _this.cancelChooseUserModal();
      },
      // 会话列表
      getSessionData: function () {
        var _this = this;
        if (Nim.getSyncDoneStatus() != true) {// IM未登录
          setTimeout(function () {
            _this.getSessionData();
          }, 1000);
          return false;
        }
        var newslist = Nim.getSessions();
        var newslen = newslist.length;
        var newNewsList = [];
        var myFriendsList = [];
        var Nimdata = Nim.getNimdata();
        var getAlltean = false;
        var getAlluser = false;
        for (var i = 0; i < newslen; i++) {
          var datetime = Utils.toChatFormatTimeDiff(newslist[i].updateTime);
          if (!newslist[i].to) {
            continue;
          }
          var nickname = '';
          if (newslist[i].type && newslist[i].type == 'custom') {
            var id = newslist[i].id;
            var Arr = id.split('-');
            var idtype = Arr[1] ? Arr[1] : '';
            if (idtype == 'gonggao') {
              nickname = '公告系统通知';
            } else if (idtype == 'richeng') {
              nickname = '日程系统通知';
            } else {//system
              nickname = '系统通知';
            }
            var text = '';
            if (newslist[i].lastMsg && newslist[i].lastMsg.text) {
              text = newslist[i].lastMsg.text.replace(/<br>/g, '');
            }
            var newsitem = {
              id: newslist[i].id,
              img: '',
              text: text,
              name: newslist[i].to,
              nickName: nickname,
              imgNickName: '通知',
              time: datetime,
              type: newslist[i].type,
              scene: newslist[i].scene,
              num: newslist[i].unread,
              idtype: idtype,
            };
          } else {
            if (newslist[i].scene == 'p2p') {
              var nicknameid = newslist[i].to;
              nickname = Nim.getUsername(nicknameid);
              if (nickname == nicknameid) {
                getAlluser = true;
              }
            } else if (newslist[i].scene == 'team') {
              var nicknameid = newslist[i].to;
              nickname = Nim.getUsername(nicknameid);
              if (nickname == nicknameid) {
                getAlltean = true;
              }
            }
            var img = Nim.getUserImg(nicknameid);

            var imgNickName = '';
            var myusername = localStorage.getItem('username');
            // 头像上的文字
            if (nickname.length == 2) {
              imgNickName = nickname;
            } else if (nickname.length == 3) {
              imgNickName = nickname.substring(1, 3);
            } else {
              if (nickname.length > 0) {
                imgNickName = nickname.substring(nickname.length - 1,
                  nickname.length);
              }
            }
            if (newslist[i].scene == 'p2p' && newslist[i].to != myusername) {
              var feiendsObj = {
                userid: newslist[i].to,
                username: nickname,
                userImg: img,
                imgNickName: imgNickName,
                scene: 'p2p',
              };
              myFriendsList.push(feiendsObj); // 最近联系人

            } else if (newslist[i].scene == 'team') {
              imgNickName = '群组';
              var feiendsObj = {
                userid: newslist[i].id,
                username: nickname,
                userImg: '',
                imgNickName: imgNickName,
                scene: 'team',
              };
              myFriendsList.push(feiendsObj); // 最近联系人
            }
            var text = '';
            if (newslist[i].lastMsg && newslist[i].lastMsg.file) {
              text = '[文件]';
              var ext = newslist[i].lastMsg.file.ext || '';
              var img_range = ['jpg', 'png', 'gif', 'jpeg', 'psd', 'bmp'];
              if (img_range.indexOf(ext) > -1) {
                text = '[图片]';
              }
            }
            if (newslist[i].lastMsg && newslist[i].lastMsg.attach) {
              text = '[通知]';
            }
            if (newslist[i].lastMsg && newslist[i].lastMsg.content) {
              var lastMsg_content = newslist[i].lastMsg.content;
              var lastMsg_contentObj = String.toJson(lastMsg_content);
              var lastMsg_type = newslist[i].lastMsg.type;
              var lastMsg_contentObj_type = lastMsg_contentObj.type;
              if (lastMsg_type == 'custom' && lastMsg_contentObj_type == 'deleteMsg') {
                text = '[通知]';
              } else if (lastMsg_type == 'custom' && lastMsg_contentObj_type == 'card') {
                text = '[群公告]';
              }
            }
            if (newslist[i].lastMsg && newslist[i].lastMsg.text) {
              text = newslist[i].lastMsg.text.replace(/<br>/g, '');
            }
            var msgType = '';
            if (newslist[i].lastMsg && newslist[i].lastMsg.type) {
              msgType = newslist[i].lastMsg.type;
            }
            var newsitem = {
              id: newslist[i].id,
              img: img,
              name: newslist[i].to,
              nickName: nickname,
              imgNickName: imgNickName,
              text: text,
              time: datetime,
              type: newslist[i].scene,
              scene: newslist[i].scene,
              num: newslist[i].unread,
              msgType: msgType,
            };
          }
          newNewsList.push(newsitem);
        }
        if (getAlltean == true) {
          _this.getAllteam();
        }
        if (getAlluser == true) {
          _this.getAlluser();
        }
        _this.messageList = newNewsList;
        console.log('newNewsList', newNewsList);
      },
      // 点击会话加载消息
      onUpdateMsg: function (el) {
        var _this = this;
        var sid = el.id;
        if (sid == 'sys-system') {//系统通知
          _this.systemPage = true;
          _this.$nextTick(function () {
            var height = $('#mag-card').height();
            var H = height - 55 - 10;
            $('#mag-card .msg-div').height(H);
          });
        } else {
          _this.systemPage = false;
          _this.$nextTick(function () {
            var height = $('#mag-card').height();
            var H = height - 41 - 101 - 41 - 51 - 10;
            $('#mag-card .msg-div').height(H);
          });
        }
        _this.sid = sid;
        var Arr = sid.split('-');
        var scene = Arr[0] ? Arr[0] : '';
        var toAccount = Arr[1] ? Arr[1] : '';
        _this.scene = scene;
        _this.toAccount = toAccount;
        _this.titleName = el.nickName;
        var _data = {
          sid: sid,
          page: 'open',
        };
        _this.onUpdateMsgList(_data);
        _this.showChatList = true;
        _this.heidChatDetail();
      },
      // 加载消息
      onUpdateMsgList: function (_data) {
        var _this = this;
        var sid = _data.sid;
        if (sid != _this.sid) {
          return false;
        }
        var page = _data.page || '';
        var msgs = Nim.getMsgs();
        var chat_list = [];
        if (msgs) {
          chat_list = msgs[sid] || [];
        }
        if (chat_list != undefined && chat_list != [] && chat_list != null && chat_list.length > 0) {
          var chatArr = [];
          var img_range = ['jpg', 'png', 'gif', 'jpeg', 'psd', 'bmp'];
          var chatlist_len = chat_list.length;
          var chatlist_start = (chatlist_len >= _this.showListLength) ? (chatlist_len - _this.showListLength) : 0;

          var haveUser = false;
          for (var i = chatlist_start; i < chatlist_len; i++) {

            var item = _this.returnObj(chat_list[i]);
            if (item.haveUser && item.haveUser == true) {
              haveUser = true;
            }
            chatArr.push(item);
          }
          if (haveUser == true) {
          }
          _this.messagesData = chatArr;
          console.log('chatArr', chatArr);
          var lastMsg = msgs[sid][chatlist_len - 1];
          _this.lastMsg = lastMsg;
          // 如果不是在聊天页面 不执行已读回调
          if (page == 'open') {
            // 标记为已读
            Nim.resetSessionUnread(sid, lastMsg);
          }
          // 判断图片加载状况，加载完成后回调
          isImgLoad(function () {
            // 加载完成
            console.log('图片加载完毕');
            //将滚动条保持在最底部
            if (_this.showListLength > _this.costShowListLength) {
              var oldshowListLength = _this.oldshowListLength;
            } else {
              var div = document.getElementById('msg-div');
              if (div) {
                div.scrollTop = div.scrollHeight;
              }
            }
          });
          var t_img; // 定时器
          var isLoad = true; // 控制变量
          // 判断图片加载的函数
          function isImgLoad(callback) {
            // 注意我的图片类名都是img，因为我只需要处理img。其它图片可以不管。
            // 查找所有封面图，迭代处理
            $('.message-image img').each(function () {
              // 找到为0就将isLoad设为false，并退出each
              if (this.height === 0) {
                isLoad = false;
                return false;
              }
            });
            // 为true，没有发现为0的。加载完毕
            if (isLoad) {
              clearTimeout(t_img); // 清除定时器
              // 回调函数
              callback();
              // 为false，因为找到了没有加载完成的图，将调用定时器递归
            } else {
              isLoad = true;
              t_img = setTimeout(function () {
                isImgLoad(callback); // 递归扫描
              }, 500); // 我这里设置的是500毫秒就扫描一次，可以自己调整
            }
          }

        }
        else {
          _this.messagesData = [];
        }
      },
      // 处理消息数据
      returnObj: function (chat_list) {
        var _this = this;
        var id_time = chat_list.time;
        var chat_time = Utils.timestampToFormatDatetime(chat_list.time);
        var isRead = Nim.getNim().isMsgRemoteRead(chat_list);//是否已读
        //表情处理
        var str = chat_list.text;
        //var textDeal = str.replace(/<br>/g, '\r\n');
        var textDeal = str;
        var messages_image = '';
        var img_range = ['jpg', 'png', 'gif', 'jpeg', 'psd', 'bmp'];
        // 接受信息为文件时处理
        var fileObj = {
          "name": "",
          "url": "",
          "size": '',
          "md5": "",
          "ext": "",
          "type": ""
        };
        if (chat_list.type == 'file') {
          var file_type = (img_range.indexOf(chat_list.file.ext) > -1)
            ? 'img' : chat_list.file.ext;
          var size = Utils.computeFileSize(chat_list.file.size);
          fileObj = {
            "name": chat_list.file.name,
            "url": chat_list.file.url,
            "size": size,
            "md5": chat_list.file.md5,
            "ext": chat_list.file.ext,
            "type": file_type
          };
          messages_image = chat_list.file.url;
        }
        var addTeamMembers = '';// 被邀请加入群的人员
        var haveUser = false;
        if ('team' == chat_list.scene && 'notification' == chat_list.type) {//群通知
          var attach = chat_list.attach || {};
          var atype = attach.type || '';
          if ('addTeamMembers' == atype || 'removeTeamMembers' == atype || 'addTeamManagers' == atype || 'removeTeamManagers' == atype) {//加成员,踢人,加管理员，减管理员
            var accounts = attach.accounts || [];
            var nameArr = [];
            for (var k in accounts) {
              if (!accounts[k]) {
                continue;
              }
              var uid = accounts[k];
              var name = Nim.getUsername(uid);
              if (name == uid) {
                haveUser = true;
              } else {
                nameArr.push(name);
              }
            }
            if (nameArr.length > 0) {
              addTeamMembers = nameArr.join(",");
            }
          } else if ('updateTeam' == atype || 'leaveTeam' == atype) {// 改群名, 退群
            var accounts = attach.users || [];
            var nameArr = [];
            for (var k in accounts) {
              if (!accounts[k]) {
                continue;
              }
              var uid = accounts[k].account;
              var name = Nim.getUsername(uid);
              if (name == uid) {
                haveUser = true;
              } else {
                nameArr.push(name);
              }
            }
            if (nameArr.length > 0) {
              addTeamMembers = nameArr.join(",");
            }
          } else if ('transferTeam' == atype) {
            var uid = attach.team.owner;
            var name = Nim.getUsername(uid);
            if (name == uid) {
              haveUser = true;
            } else {
              addTeamMembers = name;
            }

          }
        }
        var nicknameid = chat_list.from;
        var img = Nim.getUserImg(nicknameid);

        var imgNickName = '';
        var from = chat_list.from;
        var nickname = Nim.getUsername(from);
        // 头像上的文字
        if (nickname.length == 2) {
          imgNickName = nickname;
        } else if (nickname.length == 3) {
          imgNickName = nickname.substring(1, 3);
        } else {
          if (nickname.length > 0) {
            imgNickName = nickname.substring(nickname.length - 1, nickname.length);
          }
        }
        var user_self = Util.toJson(localStorage.getItem('userInfo')).username;
        var user_name = Nim.getUsername(user_self);
        var messages_type = '';
        if (user_self == from) {
          messages_type = 'sent';
        } else {
          messages_type = 'received';
        }
        // 有人@我
        var isShowIt = chat_list.isShowIt;
        if (user_self != from && (textDeal.indexOf('@' + user_name) > -1 || textDeal.indexOf('@全体成员') > -1) && _this.show_itme_div == false && isShowIt != true) {
          _this.show_itme_name = nickname;
          _this.show_itme_time = id_time;
          _this.show_itme_div = true;
        }
        var messages_avatar = '';
        var item = {
          "messages_name": nickname + ' ' + chat_time,
          "messages_avatar": messages_avatar,
          "messages_type": messages_type,
          "messages_text": textDeal,
          "messages_image": messages_image,
          "file": fileObj,
          "img": img,
          "scene": chat_list.scene,
          "from": chat_list.from,
          "fromNick": nickname,
          "imgNickName": imgNickName,
          "fromClientType": chat_list.fromClientType ? chat_list.fromClientType : '',
          "fromDeviceId": chat_list.fromDeviceId ? chat_list.fromDeviceId : '',
          "to": chat_list.to,
          "time": chat_time,
          "times": chat_list.time,
          "type": chat_list.type,
          "text": textDeal,
          "isHistoryable": chat_list.isHistoryable,
          "isRoamingable": chat_list.isRoamingable,
          "isSyncable": chat_list.isSyncable,
          "cc": chat_list.cc,
          "isPushable": chat_list.isPushable,
          "isOfflinable": chat_list.isOfflinable,
          "isUnreadable": chat_list.isUnreadable,
          "needPushNick": chat_list.needPushNick,
          "isLocal": chat_list.isLocal,
          "resend": chat_list.resend ? chat_list.resend : '',
          "idClient": chat_list.idClient ? chat_list.idClient : '',
          "idServer": chat_list.idServer ? chat_list.idServer : '',
          "userUpdateTime": chat_list.userUpdateTime ? chat_list.userUpdateTime : '',
          "status": chat_list.status,
          "attach": chat_list.attach ? chat_list.attach : {},
          "content": chat_list.content ? String.toJson(chat_list.content) : '',
          "target": chat_list.target,
          "sessionId": chat_list.sessionId,
          "flow": chat_list.flow,
          "isRead": isRead,
          "addTeamMembers": addTeamMembers,
          "chat_list": String.toStr(chat_list),
          "haveUser": haveUser
        };
        return item;
      },
      // 发送消息
      sendMessage: function () {
        const _this = this;
        var textarea_val = _this.textarea_val;
        const text = textarea_val.replace(/\n/g, '<br>').trim();
        if (text == '') {
          _this.$Message.error('消息不能为空!');
          return false;
        }
        // Mock response 避免重复发送
        if (_this.responseInProgress) return;
        _this.responseInProgress = true;

        var nim = Nim.getNim();
        var char_id = _this.sid;
        var Arr = char_id.split('-');
        var scene = Arr[0] ? Arr[0] : '';
        var toAccount = Arr[1] ? Arr[1] : '';
        if (toAccount == '') {
          _this.$Message.error('发送对象不能为空!');
          return false;
        }
        var msg = nim.sendText({
          scene: scene,
          to: toAccount,
          text: text,
          done: _sendMsgDone
        });

        function _sendMsgDone(error, msg) {
          _this.responseInProgress = false;
          if (!error) {
            _this.textarea_val = '';
            Nim.pushMsg(msg);
            var item = _this.returnObj(msg);
            _this.messagesData.push(item);
            _this.scrollHeight();//滚动
            _this.resetSessionUnread(msg.sessionId, msg);//标为已读
          } else {
            _this.$Message.error("发送失败!错误信息为\n" + error.message);
          }
        }
      },
      // 选择文件
      GetFile: function () {
        var _this = this;
        document.getElementById("chatDFileUrl").click();
      },
      // 选择文件后触发
      sendFileClick: function () {
        var _this = this;
        var __this = document.getElementById("chatDFileUrl");
        var fileObj = __this.files[0];
        var type = fileObj.type;
        var name = fileObj.name;

        _this.sendFileToAccount('chatDFileUrl');
      },
      // 发送文件
      sendFileToAccount: function (fileInput) {
        var _this = this;
        var char_id = _this.sid;
        var Arr = char_id.split('-');
        var id = Arr[1] ? Arr[1] : '';
        var scene = Arr[0] ? Arr[0] : '';
        var nim = Nim.getNim();

        var type = 'file';
        nim.previewFile({
          type: type,
          fileInput: fileInput,
          uploadprogress: function (obj) {
          },
          done: function (error, file) {
            if (!error) {
              if (id) {
                var to = id;
                var msg = nim.sendFile({
                  scene: scene,
                  to: to,
                  file: file,
                  done: _sendFileDone
                });
              }
              // 发送成功
              function _sendFileDone(error, msg) {
                if (!error) {
                  Nim.pushMsg(msg);
                  var item = _this.returnObj(msg);
                  _this.messagesData.push(item);
                  _this.scrollHeight();//滚动
                  _this.resetSessionUnread(msg.sessionId, msg);//标为已读
                } else {
                  _this.$Message.error("发送失败!错误信息为\n" + error.message);
                }
              }
            } else {
              _this.$Message.error("发送失败!错误信息为\n" + error.message);
            }
          }
        });
      },
      // 下载文件
      DownloadFile: function (url, name) {
        var _this = this;
        new FileDownloader({
          url: encodeURI(url),
          filename: name
        });
      },
      // 弹出新建群公告界面
      addTeamNotice: function () {
        var _this = this;
        _this.saveLoading = false;
        _this.addTeamNoticeModal = true;
      },
      // 添加群公告
      saveTeamNotice: function () {
        var _this = this;
        var char_id = _this.sid;
        var Arr = char_id.split('-');
        var scene = Arr[0] ? Arr[0] : '';
        var tid = Arr[1] ? Arr[1] : '';
        var chat_group_id = Nim.getNoToId(tid);
        if (tid == '') {
          _this.$Message.error('发送对象不能为空!');
          return false;
        }
        var title = _this.addTeamNoticeFrom.title;
        var content = _this.addTeamNoticeFrom.content;
        if (title == '') {
          _this.$Message.error("请输入标题!");
          return false;
        }
        if (content == '') {
          _this.$Message.error("请输入内容!");
          return false;
        }
        var data = {
          tid: tid,
          chat_group_id: chat_group_id,
          title: title,
          content: content,
        };
        var params = {
          url: '/chat/group/notice/add',
          //domain: 'https://sd.jnaw.top/sd2-mock',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            var _data = res.data || [];
            var id = _data.id;
            var data = {
              id: id,
              title: title,
            };
            _this.sendTeamNoticeToIM(data);
            _this.addTeamNoticeModal = false;
            _this.addTeamNoticeFrom.title = '';
            _this.addTeamNoticeFrom.content = '';
          } else {
            _this.$Message.error('添加群公告失败!');
          }
        }
      },
      // 取消群公告
      cancelTeamNotice: function () {
        var _this = this;
        _this.addTeamNoticeModal = false;
        _this.saveLoading = false;
        _this.addTeamNoticeFrom.title = '';
        _this.addTeamNoticeFrom.content = '';
      },
      // 发送群公告 IM消息
      sendTeamNoticeToIM: function (data) {
        var _this = this;
        var id = data.id;
        var title = data.title;

        var nim = Nim.getNim();

        var sid = _this.sid;
        var sidArr = sid.split('-');
        var type = sidArr[0];
        var tid = sidArr[1] || '';
        var username = JSON.parse(localStorage.getItem("userInfo")).username;
        var name = JSON.parse(localStorage.getItem("userInfo")).name;
        var content = {
          type: 'card',
          data: {
            id: id,
            title: title,
            name: name,
            username: username,
            time: Utils.getCurDatetime()
          }
        };
        var msg = nim.sendCustomMsg({
          scene: 'team',
          to: tid,
          content: String.toStr(content),
          done: _sendMsgDone
        });

        function _sendMsgDone(error, msg) {
          if (!error) {
            Nim.pushMsg(msg);
            var item = _this.returnObj(msg);
            _this.messagesData.push(item);
            _this.scrollHeight();//滚动
            _this.resetSessionUnread(msg.sessionId, msg);//标为已读
          } else {
            _this.$Message.error('发送群公告失败!');
          }
        }
      },
      // 查看群公告详情
      teamNoticeDetail: function (data) {
        var _this = this;
        var id = data.id;
        _this.teamNotice_id = id;
        _this.readUpdate();
      },
      // 获取群公告详情
      getTeamNoticeDetail: function (id) {
        var _this = this;
        var data = {
          id: id,
        };
        var params = {
          url: '/chat/group/notice/query',
          //domain: 'https://sd.jnaw.top/sd2-mock',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || {};
            _this.TeamNoticeDetailObj = _data;
            _this.showTeamNoticeDetailModal = true;
          } else {
            _this.$Message.error('查询群公告失败!');
          }
        }
      },
      // 已读未读,分页条
      readList_changePage: function (page) {
        var _this = this;
        _this.readList_page = page;
        _this.getReadList();
      },
      // 更新已读
      readUpdate: function () {
        var _this = this;
        var data = {
          tid: _this.teamNotice_id,
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          type: 'chat_notice',
        };
        var params = {
          url: '/read/status/update',
          //domain: 'https://sd.jnaw.top/sd2-mock',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {

          } else {

          }
          _this.getTeamNoticeDetail(_this.teamNotice_id);
          _this.getReadList(_this.teamNotice_id);
        }
      },
      // 查看已读列表
      getReadList: function (id) {
        var _this = this;
        var data = {
          tid: id,
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          type: 'chat_notice',
          page: _this.readList_page,
          size: _this.size,
        };
        var params = {
          url: '/read/status/list',
          //domain: 'https://sd.jnaw.top/sd2-mock',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            _this.readList_total = res.rows || 0;
            _this.readList = res.data ? res.data : [];
          } else {
            _this.$Message.error('查询已读人员列表失败!');
          }
        }
      },
      // 显示右侧详细信息
      showChatDetail: function () {
        var _this = this;
        _this.getTreeData();
        if (_this.scene == 'p2p') {
          var username = _this.toAccount;
          var id = Nim.getNoToId(username);
          var name = Nim.getUsername(username);
          var userImg = Nim.getUserImg(username);
          var imgNickName = '';
          // 头像上的文字
          if (name.length == 2) {
            imgNickName = name;
          } else if (name.length == 3) {
            imgNickName = name.substring(1, 3);
          } else {
            if (name.length > 0) {
              imgNickName = name.substring(name.length - 1,
                name.length);
            }
          }
          var ChatDetailImage = [];
          var obj = {
            id: id,
            name: name,
            username: username,
            thumb: userImg,
            imgNickName: imgNickName,
          };
          ChatDetailImage.push(obj);
          _this.ChatDetailImage = ChatDetailImage;

          _this.showChatDetailPage = true;

        } else if (_this.scene == 'team') {
          var id = Nim.getNoToId(_this.toAccount);
          var data = {
            id: id,
            uid: Util.toJson(localStorage.getItem('userInfo')).id,
          };
          var params = {
            url: '/chat/group/query',
            type: Util.method.get,
            data: data,
            success: _successFun
          };
          Util.ajax(_this, params);
          function _successFun(res) {
            if (res.result == 0) {
              var _data = res.data;
              _this.TeamDetailObj = _data;
              if (_data.id == 1) { // 大群不能退出
                _this.teamBig = true;
              } else {
                _this.teamBig = false;
              }
              var ChatDetailImage = [];
              // 群主
              var owner = _data.owner || {};
              var owner_id = owner.id;
              var owner_name = owner.name;
              var owner_username = owner.username;
              var userImg = Nim.getUserImg(owner_username);
              var imgNickName = '';
              // 头像上的文字
              if (owner_name.length == 2) {
                imgNickName = owner_name;
              } else if (owner_name.length == 3) {
                imgNickName = owner_name.substring(1, 3);
              } else {
                if (owner_name.length > 0) {
                  imgNickName = owner_name.substring(owner_name.length - 1,
                    owner_name.length);
                }
              }
              var obj = {
                id: owner_id,
                name: owner_name,
                username: owner_username,
                thumb: userImg,
                imgNickName: imgNickName,
              };
              ChatDetailImage.push(obj);
              if (owner_id == Util.toJson(localStorage.getItem('userInfo')).id) {
                _this.teamOwner = true; // 群主
              } else {
                _this.teamOwner = false;
              }
              // 群管理员
              var admins = _data.admins || [];
              for (var u in admins) {
                var id = admins[u].id;
                var username = admins[u].username;
                var name = admins[u].name;
                var userImg = Nim.getUserImg(username);
                var imgNickName = '';
                // 头像上的文字
                if (name.length == 2) {
                  imgNickName = name;
                } else if (name.length == 3) {
                  imgNickName = name.substring(1, 3);
                } else {
                  if (name.length > 0) {
                    imgNickName = name.substring(name.length - 1,
                      name.length);
                  }
                }
                var obj = {
                  id: id,
                  name: name,
                  username: username,
                  thumb: userImg,
                  imgNickName: imgNickName,
                };
                ChatDetailImage.push(obj);
                if (id == Util.toJson(localStorage.getItem('userInfo')).id) {
                  _this.teamAdmins = true; // 群管理员
                } else {
                  _this.teamAdmins = false;
                }
              }
              // 群成员
              var users = _data.members || [];
              for (var u in users) {
                var id = users[u].id;
                var username = users[u].username;
                var name = users[u].name;
                var userImg = Nim.getUserImg(username);
                var imgNickName = '';
                // 头像上的文字
                if (name.length == 2) {
                  imgNickName = name;
                } else if (name.length == 3) {
                  imgNickName = name.substring(1, 3);
                } else {
                  if (name.length > 0) {
                    imgNickName = name.substring(name.length - 1,
                      name.length);
                  }
                }
                var obj = {
                  id: id,
                  name: name,
                  username: username,
                  thumb: userImg,
                  imgNickName: imgNickName,
                };
                ChatDetailImage.push(obj);
              }
              _this.ChatDetailImage = ChatDetailImage;

              _this.showChatDetailPage = true;
              _this.ChatDetailPageHeight();
            } else {
              _this.$Message.error('查询群信息失败!');
            }
          }
        }
      },
      // 右侧详细信息高度
      ChatDetailPageHeight: function () {
        var _this = this;
        _this.$nextTick(function () {
          var height = $('.ChatDetailPage-Card').height();
          var H = height - 51 - 40;
          $('.ChatDetailPage-Card .ivu-card-body').height(H);
        });
      },
      // 隐藏右侧详细信息
      heidChatDetail: function () {
        var _this = this;
        _this.showChatDetailPage = false;
      },
      // 创建群
      addTeam: function () {
        var _this = this;
        var addTeamName = _this.addTeamName;
        var ChooseDepArr = _this.ChooseDepArr;
        var ChooseUserArr = _this.ChooseUserArr;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          name: addTeamName,
          users: ChooseUserArr,
          admins: [],
          departments: ChooseDepArr,
        };
        var params = {
          url: '/chat/group/add',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            var data = res.data || [];
            var id = data.id;
            var no = data.no;
            var name = data.name;
            var data_usersObj = Nim.getUsersObj();
            if (!data_usersObj[no]) {
              data_usersObj[no] = {
                id: '',
                no: no,
                name: '',
                image: ''
              };
            }
            data_usersObj[no].id = id;
            data_usersObj[no].name = name;
            Nim.setUsersObj(data_usersObj);

            _this.sid = 'team-' + no;
            _this.scene = 'team';
            _this.toAccount = no;
            _this.titleName = name;
            _this.showChatList = true;

            _this.cancelChooseUserModal();
            _this.heidChatDetail();
            var _data = {
              sid: _this.sid,
              page: 'open',
            };
            _this.onUpdateMsgList(_data);
            _this.$Message.success('创建群组成功!');
          } else {
            _this.$Message.error('创建群组失败!');
          }
        }

      },
      // 群加人
      addTeamMembers: function () {
        var _this = this;
        var ChooseDepArr = _this.ChooseDepArr;
        var ChooseUserArr = _this.ChooseUserArr;
        var no = _this.toAccount;
        var id = Nim.getNoToId(no);
        var data = {
          id: id,
          action: 'add',
          users: ChooseUserArr,
          departments: ChooseDepArr,
        };
        var params = {
          url: '/chat/group/adjust',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            var data = res.data || [];

            _this.cancelChooseUserModal();
            _this.showChatDetail();
          } else {
            _this.$Message.error('添加失败!');
          }
        }
      },
      // 显示群减人
      delTeamMembers: function () {
        var _this = this;
        var delChooseUserData = [];
        var ChatDetailImage = _this.ChatDetailImage;
        for (var k in ChatDetailImage) {
          if (!ChatDetailImage[k]) {
            continue;
          }
          var obj = {
            id: ChatDetailImage[k].id,
            name: ChatDetailImage[k].name,
            username: ChatDetailImage[k].username,
          };
          var uid = Util.toJson(localStorage.getItem('userInfo')).id;
          if (uid == ChatDetailImage[k].id) {
            obj._disabled = true;
          }
          delChooseUserData.push(obj);
        }
        _this.delChooseUserData = delChooseUserData;
        _this.delChooseUserModal = true;
      },
      // 删除群成员选中的人
      delUserSelection: function (selection) {
        var _this = this;
        var delUserArr = [];
        for (var k in selection) {
          if (!selection[k]) {
            continue;
          }
          delUserArr.push(selection[k].id);
        }
        _this.delUserArr = delUserArr;
      },
      // 取消删除群成员
      cancelDelChooseUserModal: function () {
        var _this = this;
        _this.delChooseUserModal = false;
      },
      // 删除群成员 确定
      saveDelChooseUserModal: function () {
        var _this = this;
        var delUserArr = _this.delUserArr;
        if (delUserArr.length == 0) {
          _this.$Message.error('请选择要删除的人员!');
          return false;
        }
        var no = _this.toAccount;
        var id = Nim.getNoToId(no);
        var data = {
          id: id,
          action: 'remove',
          users: delUserArr
        };
        var params = {
          url: '/chat/group/adjust',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            var data = res.data || [];

            _this.cancelDelChooseUserModal();
            _this.showChatDetail();
          } else {
            _this.$Message.error('删除失败!');
          }
        }
      },
      // 显示选人界面
      p2pShowChooseUserModal: function () {
        var _this = this;
        _this.addTeamName = '';
        _this.p2pChooseUserModal = true;
        _this.chooseUserModal = true;
      },
      // 显示选人界面
      showChooseUserModal: function () {
        var _this = this;
        _this.addTeamName = '';
        _this.p2pChooseUserModal = false;
        _this.chooseUserModal = true;
      },
      // 取消选人界面
      cancelChooseUserModal: function () {
        var _this = this;
        _this.chooseUserModal = false;
        _this.addTeamName = '';
        _this.p2pChooseUserModal = false;
      },
      // 选人 保存
      saveChooseUserModal: function () {
        var _this = this;
        var CheckedNodes = _this.$refs.tree.getCheckedNodes();
        if (_this.p2pChooseUserModal == true && _this.addTeamName == '') {
          _this.$Message.error('请输入群名称!');
          return false;
        }
        if (CheckedNodes.length == 0) {
          _this.$Message.error('请选择人员!');
          return false;
        }
        var depArr = [];
        var userArr = [];
        var usernameArr = [];
        for (var k in CheckedNodes) {
          if (!CheckedNodes[k]) {
            continue;
          }
          var id = CheckedNodes[k].id;
          var username = CheckedNodes[k].username || '';
          var type = CheckedNodes[k].type;
          if (type == 'dep') {
            depArr.push(id);
          } else if (type == 'user') {
            userArr.push(id);
            usernameArr.push(username);
          }
        }
        _this.ChooseDepArr = depArr;
        _this.ChooseUserArr = userArr;
        _this.ChooseUsernameArr = usernameArr;
        if (_this.forwarPage != true && _this.scene == 'p2p') {
          _this.addTeam();
        } else if (_this.forwarPage != true && _this.scene == 'team') {
          _this.addTeamMembers();
        } else if (_this.forwarPage == true) {//转发消息
          _this.forwardingMsgFun();
          _this.cancelChooseUserModal();
        }
      },
      // 获取选人 树信息
      getTreeData: function () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
          id: 1
        };
        var params = {
          url: '/department/query',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var data = res.data || [];
            var TreeData = [];
            TreeData.push(data);
            _this.toDataFun(TreeData);
            _this.TreeData = TreeData;
          } else {
            _this.$Message.error('查询人员信息失败!');
          }
        }
      },
      // 处理树信息
      toDataFun: function (arr) {
        var _this = this;
        arr.forEach(function (e) {
          e.title = e.name;
          e.expand = true;//展开
          if (e.type) {
            e.type = 'dep';
          } else {
            e.type = 'user';
            var ChatDetailImage = _this.ChatDetailImage;
            if (Utils.idInArray(e.id, ChatDetailImage)) {
              e.checked = true;// 选中
            }
          }
          var staff = e.staff || [];
          var children = e.children || [];
          if (children.length == 0) {
            e.children = [];
          }
          e.children.push(...staff);
          _this.toDataFun(e.children);
        });
      },
      // 退出群
      quitTeam: function () {
        var _this = this;
        _this.$Modal.confirm({
          title: '温馨提示',
          content: '<p>确认退出该群组？</p>',
          onOk: () => {
            var no = _this.toAccount;
            var id = Nim.getNoToId(no);
            var data = {
              id: id,
            };
            var params = {
              url: '/chat/group/quit',
              type: Util.method.get,
              data: data,
              success: _successFun
            };
            Util.ajax(_this, params);
            function _successFun(res) {
              if (res.result == 0) {
                var Nimdata = Nim.getNimdata();
                if (Nimdata.msgs) Nimdata.msgs[_this.sid] = [];
                Nim.setNimdata(Nimdata);
                _this.heidChatDetail();
                _this.showChatList = false;
              } else {
                _this.$Message.error('退出群组失败!');
              }
            }
          },
          onCancel: () => {
          }
        });
      },
      // 解散群
      delTeam: function () {
        var _this = this;
        _this.$Modal.confirm({
          title: '温馨提示',
          content: '<p>确认解散该群组？</p>',
          onOk: () => {
            var no = _this.toAccount;
            var id = Nim.getNoToId(no);
            var data = {
              id: id,
            };
            var params = {
              url: '/chat/group/delete',
              type: Util.method.get,
              data: data,
              success: _successFun
            };
            Util.ajax(_this, params);
            function _successFun(res) {
              if (res.result == 0) {
                var Nimdata = Nim.getNimdata();
                if (Nimdata.msgs) Nimdata.msgs[_this.sid] = [];
                Nim.setNimdata(Nimdata);
                _this.heidChatDetail();
                _this.showChatList = false;
              } else {
                _this.$Message.error('解散群组失败!');
              }
            }
          },
          onCancel: () => {
          }
        });
      },
      // 显示修改群名称
      showUpdateTeamName: function () {
        var _this = this;
        _this.updateTeamName = _this.TeamDetailObj.name;
        _this.updateTeamNameModal = true;
      },
      // 隐藏修改群名称
      hideUpdateTeamName: function () {
        var _this = this;
        _this.updateTeamNameModal = false;
      },
      // 修改群名称
      updateTeamNameFun: function () {
        var _this = this;
        var updateTeamName = _this.updateTeamName;
        if (updateTeamName == '') {
          _this.$Message.error('请输入群名称!');
          return false;
        }
        var no = _this.toAccount;
        var id = Nim.getNoToId(no);
        var data = {
          id: id,
          name: updateTeamName,
        };
        var params = {
          url: '/chat/group/update',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            var data_usersObj = Nim.getUsersObj();
            if (!data_usersObj[_this.toAccount]) {
              data_usersObj[_this.toAccount] = {
                id: id,
                no: _this.toAccount,
                name: '',
                image: ''
              };
            }
            data_usersObj[_this.toAccount].name = updateTeamName;
            Nim.setUsersObj(data_usersObj);
            _this.hideUpdateTeamName();
            _this.getSessionData();
            _this.showChatDetail();
          } else {
            _this.$Message.error('修改群名称失败!');
          }
        }
      },
      // 显示调整群管理员
      showUpdateTeamAdmins: function () {
        var _this = this;
        var updateTeamAdminsData = [];
        var admins = _this.TeamDetailObj.admins;
        for (var k in admins) {
          if (!admins[k]) {
            continue;
          }
          var obj = {
            id: admins[k].id,
            name: admins[k].name,
            _checked: true
          };
          updateTeamAdminsData.push(obj);
        }
        var members = _this.TeamDetailObj.members;
        for (var k in members) {
          if (!members[k]) {
            continue;
          }
          var obj = {
            id: members[k].id,
            name: members[k].name,
          };
          updateTeamAdminsData.push(obj);
        }
        _this.updateTeamAdminsData = updateTeamAdminsData;
        _this.updateTeamAdminsModal = true;
      },
      // 隐藏调整群管理员
      hideUpdateTeamAdmins: function () {
        var _this = this;
        _this.updateTeamAdminsModal = false;
      },
      // 调整群管理员选中的人员
      updateTeamAdminsSelection: function (selection) {
        var _this = this;
        var updateTeamAdminsUserArr = [];
        for (var k in selection) {
          if (!selection[k]) {
            continue;
          }
          updateTeamAdminsUserArr.push(selection[k].id);
        }
        _this.updateTeamAdminsUserArr = updateTeamAdminsUserArr;
      },
      // 确定调整群管理员
      saveUpdateTeamAdmins: function () {
        var _this = this;
        var updateTeamAdminsUserArr = _this.updateTeamAdminsUserArr;
        var no = _this.toAccount;
        var id = Nim.getNoToId(no);
        var data = {
          id: id,
          no: no,
          action: 'setAdmins',
          admins: updateTeamAdminsUserArr,
        };
        var params = {
          url: '/chat/group/adjust',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            _this.hideUpdateTeamAdmins();
            _this.showChatDetail();
          } else {
            _this.$Message.error('调整群管理员失败!');
          }
        }
      },
      // 显示转让群
      showUpdateTeamOwner: function () {
        var _this = this;
        var updateTeamOwnerData = [];
        var admins = _this.TeamDetailObj.admins;
        for (var k in admins) {
          if (!admins[k]) {
            continue;
          }
          var obj = {
            id: admins[k].id,
            name: admins[k].name,
          };
          updateTeamOwnerData.push(obj);
        }
        var members = _this.TeamDetailObj.members;
        for (var k in members) {
          if (!members[k]) {
            continue;
          }
          var obj = {
            id: members[k].id,
            name: members[k].name,
          };
          updateTeamOwnerData.push(obj);
        }
        _this.updateTeamOwnerData = updateTeamOwnerData;
        _this.updateTeamOwnerModal = true;
      },
      // 隐藏转让群
      hideUpdateTeamOwner: function () {
        var _this = this;
        _this.updateTeamOwnerModal = false;
      },
      // 转让群 单选一个人
      updateTeamOwnerCurrent: function (currentRow, oldCurrentRow) {
        var _this = this;
        var updateTeamOwnerUserArr = [];
        updateTeamOwnerUserArr.push(currentRow.id);
        _this.updateTeamOwnerUserArr = updateTeamOwnerUserArr;
      },
      // 确定转让群
      saveUpdateTeamOwner: function () {
        var _this = this;
        if (_this.updateTeamOwnerUserArr.length == 0) {
          _this.$Message.error('请选择新群主!');
          return false;
        }
        var no = _this.toAccount;
        var id = Nim.getNoToId(no);
        var data = {
          id: id,
          no: no,
          action: 'transfer',
          owner: _this.updateTeamOwnerUserArr[0],
        };
        var params = {
          url: '/chat/group/adjust',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        _this.saveLoading = true;
        function _successFun(res) {
          _this.saveLoading = false;
          if (res.result == 0) {
            _this.hideUpdateTeamOwner();
            _this.showChatDetail();
          } else {
            _this.$Message.error('转让群失败!');
          }
        }
      },
      // 右键
      contextmenuFun: function (el, event) {
        var _this = this;
        var pageX = event.pageX;
        var pageY = event.pageY;
        $('.contextmenuPoptip').css('left', pageX);
        $('.contextmenuPoptip').css('top', pageY);
        var checkedMsg = {};
        var message = el;
        var sessionId = message.sessionId;
        var idClient = message.idClient;
        var Nimdata = Nim.getNimdata();
        var msgs = Nimdata.msgs || {};
        var ListArr = msgs[sessionId] || [];
        for (var k in ListArr) {
          var id = ListArr[k].idClient;
          if (id == idClient) {
            checkedMsg = ListArr[k];
            break;
          }
        }
        var myAccount = Util.toJson(localStorage.getItem('userInfo')).username;
        var newtime = new Date().getTime();
        var times = message.times || 0;
        var langtime = newtime - times;
        var from = message.from;//发送人id
        var to = message.to;//接收人id
        if (langtime <= (1000 * 60 * 2) && myAccount == from && myAccount != to) {
          _this.isUndoMsg = true;// 撤销
        } else {
          _this.isUndoMsg = false;
        }
        _this.isTeamNotice = false;// 转发
        var type = el.type;
        if (type == 'custom') {
          var content = el.content;
          if (content && content.type && content.type == 'card') {
            _this.isTeamNotice = true;// 群公告不能转发
          }
        }
        _this.checkedMsg = checkedMsg;
        _this.contextmenuModel = true;
      },
      // 转发
      forwardingFun: function () {
        var _this = this;
        _this.getTreeData();
        _this.showChooseUserModal();
        _this.heidChatDetail();
        _this.ChatDetailImage = [];
        _this.forwarPage = true;
        _this.contextmenuModel = false;
      },
      // 转发消息
      forwardingMsgFun: function () {
        var _this = this;
        var ChooseUsernameArr = _this.ChooseUsernameArr;
        var forwardMsg = _this.checkedMsg;
        var sessionId = forwardMsg.sessionId;
        var num = 0;
        var allnum = ChooseUsernameArr.length;

        var nim = Nim.getNim();

        function _forwardMsg(scene, to, someMsg) {
          nim.forwardMsg({
            msg: someMsg,
            scene: scene,
            to: to,
            done: _sendMsgDone
          })
        }

        function _sendMsgDone(error, msg) {
          if (!error) {
            Nim.pushMsg(msg);
            var sid = msg.sessionId;
            if (sid == sessionId) {//转发到当前聊天
              var _data = {
                sid: sessionId,
                page: 'open',
              };
              _this.onUpdateMsgList(_data);
            }
          }
          if (num == allnum) {
            num++;
            if (!error) {
              _this.$Message.success('发送成功!');
            } else {
              _this.$Message.error("发送失败!错误信息为\n" + error.message);
            }
          }
        }

        for (var k in ChooseUsernameArr) {
          var to = ChooseUsernameArr[k];
          var scene = 'p2p';
          _forwardMsg(scene, to, forwardMsg);
          num++;
        }
      },
      // 撤消
      undoFun: function () {
        var _this = this;
        var checkedMsg = _this.checkedMsg;
        var nim = Nim.getNim();
        nim.deleteMsg({
          msg: checkedMsg,
          done: deleteMsgDone
        });

        function deleteMsgDone(error, msg) {
          console.log('撤回消息' + (!error ? '成功' : '失败'), error, msg);
          if (!error) {
            _this.deleteFun();//删除消息
            var deltime = msg.msg.time;
            var scene = msg.msg.scene;
            var sessionId = msg.msg.sessionId;
            var arr = sessionId.split('-');
            var toid = arr[1];

            var myAccount = Util.toJson(localStorage.getItem('userInfo')).username;
            var name = Util.toJson(localStorage.getItem('userInfo')).name;
            var content = {
              type: 'deleteMsg',
              data: {
                text: ' 撤回了一条消息',
                name: name,
                userid: myAccount,
                time: Utils.getCurDatetime()
              }
            };
            var msg = nim.sendCustomMsg({
              scene: scene,
              to: toid,
              content: Util.toStr(content),
              done: _sendMsgDone
            });

            function _sendMsgDone(error, msg) {
              if (!error) {
                Nim.pushMsg(msg);
                var item = _this.returnObj(msg);
                _this.messagesData.push(item);
              } else {
                _this.$Message.error("发送失败!错误信息为\n" + error.message);
              }
            }
          }
        }

        _this.contextmenuModel = false;
      },
      // 删除
      deleteFun: function () {
        var _this = this;
        var message = _this.checkedMsg;
        var messagesData = _this.messagesData;
        var sessionId = message.sessionId;
        var idClient = message.idClient;
        for (var k in messagesData) {
          var id = messagesData[k].idClient;
          if (id == idClient) {
            var del = messagesData.splice(k, 1);
            break;
          }
        }
        _this.messagesData = messagesData;
        var Nimdata = Nim.getNimdata();
        var msgs = Nimdata.msgs || {};
        var ListArr = msgs[sessionId] || [];
        for (var k in ListArr) {
          var id = ListArr[k].idClient;
          if (id == idClient) {
            var del = ListArr.splice(k, 1);
            break;
          }
        }
        Nimdata.msgs[sessionId] = ListArr;
        Nim.setNimdata(Nimdata);
        _this.contextmenuModel = false;
      },

      // 获取所有用户
      getAlluser: function () {
        var _this = this;
        var data = {
          departments: [0]
        };
        var params = {
          url: '/user/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data || [];
            var users = _data || [];
            var data_usersObj = Nim.getUsersObj();
            for (var tem in users) {
              var username = users[tem].username;
              var id = users[tem].id;
              var name = users[tem].name;
              var avatar = '/vendors/images/person.png';
              if (users[tem].avatar.thumb) {
                avatar = users[tem].avatar.thumb;
              }
              if (!data_usersObj[username]) {
                data_usersObj[username] = {
                  id: '',
                  no: username,
                  name: '',
                  image: ''
                };
              }
              data_usersObj[username].id = id;
              data_usersObj[username].name = name;
              data_usersObj[username].image = avatar;
            }
            Nim.setUsersObj(data_usersObj);

            var newslist = Nim.getSessions();
            var newslen = newslist.length;
            for (var i = 0; i < newslen; i++) {
              var sid = newslist[i].id;
              var Arr = sid.split('-');
              var iid = Arr[1] ? Arr[1] : '';
              if (!data_usersObj[iid]) { // 不存在的人删掉
                var Nimdata = Nim.getNimdata();
                if (Nimdata.msgs) Nimdata.msgs[sid] = [];
                Nim.setNimdata(Nimdata);
                Nim.nim_delsessions('p2p', iid);// 删除群会话
              }
            }

            _this.getSessionData();
          } else {
            _this.$Message.error('查询用户信息失败!');
          }
        }
      },
      // 获取所有群
      getAllteam: function () {
        var _this = this;
        var data = {
          uid: Util.toJson(localStorage.getItem('userInfo')).id,
        };
        var params = {
          url: '/chat/group/list',
          type: Util.method.get,
          data: data,
          success: _successFun
        };
        Util.ajax(_this, params);
        function _successFun(res) {
          if (res.result == 0) {
            var _data = res.data;
            var data_usersObj = Nim.getUsersObj();
            var groups = _data;
            for (var k in groups) {
              var id = groups[k].id;
              var no = groups[k].no;
              var name = groups[k].name;
              var is_top = groups[k].pin;
              var mute_team = groups[k].mute;
              if (!data_usersObj[no]) {
                data_usersObj[no] = {
                  id: '',
                  no: no,
                  name: '',
                  image: ''
                };
              }
              data_usersObj[no].id = id;
              data_usersObj[no].name = name;
            }
            Nim.setUsersObj(data_usersObj);

            var newslist = Nim.getSessions();
            var newslen = newslist.length;
            for (var i = 0; i < newslen; i++) {
              var sid = newslist[i].id;
              var Arr = sid.split('-');
              var iid = Arr[1] ? Arr[1] : '';
              if (!data_usersObj[iid]) { // 不存在的群删掉
                var Nimdata = Nim.getNimdata();
                if (Nimdata.msgs) Nimdata.msgs[sid] = [];
                Nim.setNimdata(Nimdata);
                Nim.nim_delsessions('team', iid);// 删除群会话
              }
            }

            _this.getSessionData();
          } else {
            _this.$Message.error('查询群组信息失败!');
          }
        }
      },
    }
  };
</script>

<style>

</style>
